package com.openbravo.data.gui;

import java.awt.Component;

import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;

import cn.ekuma.data.dao.bean.I_Category;
import cn.ekuma.data.dao.user.tree.BrowsableTreeDataModel.CategoryTreeNode;

import com.openbravo.data.loader.IRenderString;

public class TreeCellRendererBasic extends DefaultTreeCellRenderer {
	   private IRenderString m_renderer;
	    
	    /** Creates a new instance of ListCellRendererBasic */
	    public TreeCellRendererBasic(IRenderString renderer) {
	        m_renderer = renderer;
	    }

		@Override
		public Component getTreeCellRendererComponent(JTree tree, Object value,
				boolean sel, boolean expanded, boolean leaf, int row,
				boolean hasFocus) {
			super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf,
					row, hasFocus);
			String s =null;
			I_Category category=((CategoryTreeNode)value).getCategory();
			if(category!=null)
				s=m_renderer.getRenderString(((CategoryTreeNode)value).getCategory());
	        setText((s == null || s.equals("")) ? " " : s); // Un espacio en caso de nulo para que no deja la celda chiquitita.
	        return this;
		}
	    
	    
}
